﻿using System;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Graphics;

using FarseerPhysics.Dynamics.Contacts;

namespace Spacer
{
    public class Extractor : Item
    {
		public Extractor() {}

        public Extractor( SolarSys world ) : base(world) {
			if( this.GetType() == typeof(Extractor) ) Initialize();
        }

		public override void Initialize() {
			base.Initialize();

			Texture = Main.FindTexture("Platapus");
            DrawMode = DrawMode.None;
            Name = "Extractor";
            elapsedTime = 0f;
            ResourceWorth = 2000;
		}

		// ----------

        public void GiveResources(Ship ship)
        {
            ship.Resources += ExtractedResources;
            ExtractedResources = 0;
        }

        public void ExtractResourcesFromPlanet(Planet planet)
        {
            elapsedTime += Globals.GameTime;
            if (elapsedTime >= 3000f && planet.Adamantium > 0)
            {
                planet.Adamantium -= 1000;
                ExtractedResources += 1000;
                if (planet.Adamantium < 0)
                {
                    ExtractedResources += planet.Adamantium;
                    planet.Adamantium = 0;
                }
                elapsedTime = 0;
            }
         }

        public override void DrawItemCard(Vector2 pos, Vector2 size)
        {
            Surface.DrawColor = DrawColor;

            Vector2 ItemDisplayPos = new Vector2(pos.X + size.X / 2, pos.Y);
           // Vector2 ItemNamePos = new Vector2(pos.X + size.X / 2, pos.Y + size.Y - 25);

            Surface.DrawRect(Texture, ItemDisplayPos, new Vector2(100, 100), Vector2.Zero, 0f);
            //Surface.DrawString( "DefaultSmall", ((int)ShieldAmount)+"%", ItemDisplayPos, new Vector2(0.5f,0.5f), 0f );
            //Surface.DrawString( "DefaultSmall", Name, ItemNamePos, new Vector2(0.5f,0.5f), 0f );
        }
        public int ExtractedResources { get; set; }
        public float elapsedTime { get; set; }
        // ----------
    }
}
